<?php

class NewsAction extends CommonAction
{

    public function _initialize() {
        parent::_initialize();
        C('LAYOUT_NAME', 'Layout/columns-left');
    }

    public function index() {
        $map = array();
        import("@.ORG.Util.Page");       //导入分页类
        $model = M('News');
        $keyword = $this->_get('keyword');
        $map['identify'] = '';
        if ($keyword) {
            $where['title'] = array('like', '%' . $keyword . '%');
            $where['_logic'] = 'or';
            $map['_complex'] = $where;
            $this->assign('keyword', urldecode($keyword));
        }

        $count = $model->where($map)->count();    //计算总数

        $p = new Page($count, 10);
        $rows = $model
                ->where($map)
                ->limit($p->firstRow . ',' . $p->listRows)
                ->order('news_id desc')
                ->select();
        $p->SetPager('zjj', 
                '<div class="newpager">{prev}{list}{next}</div>', 
                array(
                    "listlong" => "6", 
                    "first" => "<<", 
                    "last" => ">>", 
                    "prev" => "<", 
                    "next" => ">", 
                    "list" => "*", 
                    "jump" => "select"));
        $page = $p->show('zjj');            //分页的导航条的输出变量
        $this->assign("page", $page);
        $this->assign("rows", $rows); //数据循环变量
        $this->display('index');
    }

    public function item() {
        $id = (int) $this->_get('id');
        if (!$id) {
            $this->error('您请求的文章不存在');
        }
        $art = M('News');
        $item = $art->where('news_id = "' . $id . '"')->find();
        $this->assign('item', $item);
        $this->display('item');
    }

}